package echat.future.cn.echat.home

import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import android.widget.TextView
import com.google.gson.Gson
import com.zhusx.core.adapter._BaseRecyclerAdapter
import com.zhusx.core.app._BaseAppCompatActivity
import com.zhusx.core.utils._Views
import echat.future.cn.echat.R
import echat.future.cn.echat.home.bean.AnchorEntity
import echat.future.cn.echat.home.bean.ReplyTag
import kotlinx.android.synthetic.main.activity_activity_ta_label.*

/**
 *
 * Author  zhusx
 * Email   327270607@qq.com
 * Create  2018/9/25 21:04
 */
class TaLabelActivity : _BaseAppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_activity_ta_label)
        val en = Gson().fromJson(intent.getStringExtra(_EXTRA_String_VALUE), AnchorEntity::class.java)
        val list = mutableListOf<ReplyTag>()
        en.comment?.forEach {
            it.reply_tag?.forEach {
                list.add(it)
            }
        }
        iv_return.setOnClickListener { finish() }
        recyclerView.adapter = object : _BaseRecyclerAdapter<ReplyTag>(list) {
            override fun bindViewHolder(holder: _ViewHolder, p1: Int, p2: ReplyTag) {
                holder.setText(R.id.tv_name, p2.tag_name)
                holder.getView<TextView>(R.id.tv_name).toCornersDrawable(p2.value)
            }

            override fun getLayoutResource(p0: Int): Int = R.layout.item_label
        }
    }

    fun TextView.toCornersDrawable(color: String) {
        val drawable = GradientDrawable()
        drawable.cornerRadius = _Views.dip2px(20.toFloat()).toFloat()
        try {
            drawable.setColor(Color.parseColor(color))
        } catch (e: Exception) {
            drawable.setColor(Color.parseColor("#FF759F"))
        }
        this.setBackgroundDrawable(drawable)
    }
}